<template>
    <div @touchstart="ts($event)" @touchmove="tc" @touchend="te" @touchcancel="tc">
        <slot></slot>
    </div>
</template>

<script>

//专门用来封装长按事件
export default {
    name:"viewContent",
    data(){
        return {
            timerId:null
        }
    },
    methods:{
        ts(event){
            if(this.timerId!=null){
                return;
            }
            this.timerId = setTimeout(()=>{
                   event.preventDefault();
                   this.$emit("longpress",event)
                   clearTimeout(this.timerId)
                   this.timerId=null
            },600)
        },
        tc(){
            clearTimeout(this.timerId);
            this.timerId=null
        },
        te(){
            if(this.timerId!=null){
                clearTimeout(this.timerId)
                this.timerId=null
                this.$emit("click")
            }
        }
    }
}
</script>

<style>

</style>
